package com.wsl.thymeleafinaction.controller;

import com.wsl.thymeleafinaction.domain.User;
import com.wsl.thymeleafinaction.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 18:30 2017/12/6
 * @Modified by:
 */
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserRepository userRepository;

    /**
     * 从用户存储库  获取用户列表
     * @return
     */
    private List<User> getUserList(){
        return userRepository.listUser();
    }
    @GetMapping
    public ModelAndView list(Model model){
        model.addAttribute("userList",getUserList());
        model.addAttribute("title","用户管理");
        return new ModelAndView("users/list","userModel",model);
    }
}